/*
 * Allwinner SoCs hdmi2.0 driver.
 *
 * Copyright (C) 2016 Allwinner.
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */
#include <linux/kernel.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <stdio.h>

#include "config.h"
#include "freq_ss.h"

//length = 381
//Freq = 31.500000 KHz, AMP = 0.020000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_02[381] = {
11,  11,  10,  11,  11,  11,  11,  10,  11,  11,  11,  10,  11,  11,  11,  10,
11,  11,  11,  10,  11,  10,  11,  11,  10,  11,  10,  11,  10,  11,  10,  11,
10,  11,  10,  10,  11,  10,  10,  11,  10,  10,  10,  10,  10,  10,  10,  10,
10,  10,  10,  10,  10,  10,   9,  10,  10,   9,  10,   9,  10,   9,  10,   9,
9,  10,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   8,   9,   9,   8,
9,   8,   9,   8,   8,   9,   8,   8,   8,   8,   8,   8,   8,   7,   8,   8,
7,   8,   7,   7,   8,   7,   7,   7,   7,   7,   7,   7,   7,   6,   7,   7,
6,   7,   6,   6,   6,   6,   7,   5,   6,   6,   6,   6,   5,   6,   5,   6,
5,   5,   5,   5,   5,   5,   5,   5,   4,   5,   4,   5,   4,   4,   5,   4,
4,   4,   3,   4,   4,   3,   4,   3,   4,   3,   3,   3,   3,   3,   3,   3,
2,   3,   2,   3,   2,   2,   2,   2,   2,   2,   2,   2,   1,   2,   1,   1,
2,   1,   1,   1,   1,   0,   1,   1,   0,   1,   0,   0,   1,   0,   0,   0,
0,   0,   0,   1,   0,   1,   1,   0,   1,   1,   1,   1,   2,   1,   1,   2,
2,   1,   2,   2,   2,   2,   2,   2,   3,   2,   2,   3,   3,   2,   3,   3,
3,   3,   3,   4,   3,   3,   4,   3,   4,   4,   4,   4,   4,   4,   4,   4,
4,   5,   4,   5,   5,   4,   5,   5,   5,   5,   5,   5,   6,   5,   6,   5,
6,   5,   6,   6,   6,   6,   6,   6,   6,   6,   7,   6,   7,   6,   7,   7,
6,   7,   7,   7,   7,   7,   7,   8,   7,   7,   8,   7,   8,   7,   8,   8,
8,   8,   7,   8,   9,   8,   8,   8,   8,   9,   8,   9,   8,   9,   8,   9,
9,   8,   9,   9,   9,   9,   9,   9,   9,  10,   9,   9,   9,  10,   9,  10,
9,  10,   9,  10,   9,  10,  10,  10,   9,  10,  10,  10,  10,  10,  10,  10,
10,  10,  11,  10,  10,  10,  10,  11,  10,  10,  11,  10,  11,  10,  11,  10,
11,  10,  11,  10,  11,  10,  11,  11,  10,  11,  11,  10,  11,  11,  11,  10,
11,  11,  11,  10,  11,  11,  11,  10,  11,  11,  11,  11,   9
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.040000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_04[381] = {
22,  21,  22,  21,  22,  22,  21,  22,  21,  22,  21,  22,  21,  22,  21,  22,
21,  22,  21,  21,  22,  21,  21,  21,  22,  21,  21,  21,  21,  21,  21,  21,
21,  20,  21,  21,  21,  20,  21,  20,  21,  20,  20,  20,  21,  20,  20,  20,
20,  20,  19,  20,  20,  19,  20,  19,  19,  20,  19,  19,  19,  19,  18,  19,
19,  18,  19,  18,  18,  19,  18,  18,  17,  18,  18,  17,  18,  17,  18,  17,
17,  17,  16,  17,  17,  16,  17,  16,  16,  16,  16,  15,  16,  16,  15,  15,
15,  15,  15,  15,  15,  14,  14,  15,  14,  14,  13,  14,  14,  13,  13,  13,
13,  13,  13,  12,  13,  12,  12,  12,  12,  11,  12,  11,  11,  11,  11,  11,
11,  10,  10,  10,  10,  10,  10,   9,  10,   9,   9,   9,   8,   9,   8,   8,
8,   8,   8,   7,   8,   7,   7,   7,   6,   7,   6,   6,   6,   6,   6,   5,
5,   5,   5,   5,   5,   4,   4,   4,   4,   4,   4,   3,   3,   3,   3,   3,
2,   3,   2,   2,   1,   2,   1,   2,   1,   1,   0,   1,   0,   0,   0,   0,
0,   2,   0,   1,   1,   2,   1,   2,   1,   2,   3,   2,   2,   3,   3,   3,
3,   4,   3,   4,   4,   4,   4,   4,   5,   5,   5,   5,   5,   6,   5,   6,
6,   6,   7,   6,   7,   7,   7,   7,   7,   8,   7,   8,   8,   8,   9,   8,
9,   9,   9,   9,   9,  10,   9,  10,  10,  10,  10,  11,  10,  11,  11,  11,
11,  12,  11,  12,  12,  12,  12,  12,  12,  13,  12,  13,  13,  13,  14,  13,
14,  13,  14,  14,  14,  14,  15,  14,  15,  14,  15,  15,  16,  15,  15,  16,
15,  16,  16,  16,  16,  16,  17,  16,  17,  16,  17,  17,  17,  17,  18,  17,
17,  18,  18,  17,  18,  18,  18,  18,  19,  18,  19,  18,  19,  18,  19,  19,
19,  19,  19,  20,  19,  19,  20,  19,  20,  20,  19,  20,  20,  20,  20,  20,
21,  20,  20,  20,  21,  20,  21,  20,  21,  21,  21,  20,  21,  21,  21,  21,
21,  21,  21,  21,  22,  21,  21,  21,  22,  21,  21,  22,  21,  22,  21,  22,
21,  22,  21,  22,  21,  22,  21,  22,  22,  21,  22,  21,  20
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.060000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_06[381] = {
32,  33,  32,  33,  32,  32,  33,  32,  33,  32,  32,  32,  33,  32,  32,  32,
32,  33,  32,  32,  32,  31,  32,  32,  32,  32,  31,  32,  31,  32,  31,  32,
31,  31,  31,  31,  31,  31,  31,  31,  30,  31,  30,  31,  30,  30,  30,  30,
30,  30,  29,  30,  29,  30,  29,  29,  29,  29,  29,  28,  29,  28,  28,  28,
28,  28,  28,  27,  28,  27,  27,  27,  27,  26,  27,  26,  26,  26,  26,  26,
26,  25,  25,  25,  25,  25,  24,  25,  24,  24,  24,  23,  24,  23,  23,  23,
23,  22,  22,  22,  22,  22,  22,  21,  21,  21,  21,  20,  20,  20,  20,  20,
19,  20,  19,  18,  19,  18,  19,  17,  18,  18,  17,  17,  17,  16,  17,  16,
16,  15,  16,  15,  15,  14,  15,  14,  14,  14,  13,  13,  13,  13,  13,  12,
12,  12,  11,  11,  11,  11,  11,  10,  10,  10,   9,   9,   9,   9,   8,   9,
8,   7,   8,   7,   7,   6,   7,   6,   6,   5,   5,   6,   4,   5,   4,   4,
4,   3,   4,   2,   3,   2,   3,   1,   2,   1,   1,   1,   1,   0,   0,   0,
1,   1,   1,   1,   2,   1,   3,   2,   3,   3,   3,   3,   4,   4,   4,   5,
5,   5,   5,   6,   6,   6,   6,   7,   7,   7,   7,   8,   8,   8,   8,   9,
9,   9,  10,  10,  10,  10,  10,  11,  11,  11,  12,  12,  12,  12,  13,  12,
13,  14,  13,  14,  14,  14,  14,  15,  15,  15,  16,  15,  16,  16,  17,  16,
17,  17,  17,  18,  17,  18,  18,  19,  18,  19,  19,  19,  20,  20,  19,  21,
20,  20,  21,  21,  21,  21,  22,  22,  22,  22,  22,  23,  22,  23,  23,  23,
24,  24,  23,  24,  25,  24,  24,  25,  25,  25,  25,  26,  25,  26,  26,  26,
26,  26,  27,  27,  26,  27,  27,  28,  27,  28,  27,  28,  28,  28,  28,  29,
28,  29,  29,  28,  29,  29,  30,  29,  29,  30,  30,  29,  30,  30,  30,  30,
31,  30,  31,  30,  31,  31,  30,  31,  31,  31,  31,  32,  31,  31,  32,  31,
32,  31,  32,  32,  31,  32,  32,  32,  32,  32,  32,  32,  32,  32,  33,  32,
32,  32,  33,  32,  32,  33,  32,  32,  33,  32,  33,  32,  29
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.080000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_08[381] = {
43,  43,  44,  43,  43,  43,  43,  44,  43,  43,  43,  43,  43,  43,  43,  43,
43,  42,  43,  43,  42,  43,  42,  43,  42,  43,  42,  42,  42,  42,  42,  42,
41,  42,  41,  42,  41,  41,  41,  41,  41,  41,  40,  41,  40,  40,  41,  40,
39,  40,  40,  39,  39,  39,  39,  39,  39,  38,  38,  39,  38,  37,  38,  37,
38,  37,  37,  36,  37,  36,  36,  36,  36,  36,  35,  35,  35,  35,  34,  34,
34,  34,  34,  33,  33,  33,  33,  32,  33,  32,  31,  32,  31,  31,  31,  30,
31,  30,  29,  30,  29,  29,  29,  28,  28,  28,  28,  27,  27,  27,  26,  27,
26,  25,  26,  25,  24,  25,  24,  24,  24,  23,  23,  23,  22,  22,  22,  21,
21,  21,  21,  20,  20,  19,  20,  19,  18,  18,  18,  18,  17,  17,  17,  16,
16,  16,  15,  15,  15,  14,  14,  14,  13,  13,  13,  12,  12,  12,  11,  11,
11,  10,  10,   9,  10,   8,   9,   8,   8,   7,   7,   7,   6,   6,   6,   5,
5,   5,   4,   4,   4,   3,   3,   2,   2,   2,   2,   1,   0,   1,   0,   1,
0,   1,   2,   2,   2,   2,   3,   3,   4,   4,   4,   5,   5,   5,   6,   6,
6,   7,   7,   8,   7,   9,   8,   9,   9,  10,  10,  10,  10,  11,  12,  11,
12,  13,  12,  13,  14,  13,  14,  15,  14,  15,  16,  15,  16,  17,  16,  17,
18,  17,  18,  19,  18,  19,  20,  19,  20,  20,  21,  21,  21,  21,  22,  22,
23,  22,  23,  24,  23,  24,  24,  25,  25,  25,  25,  26,  26,  26,  26,  27,
27,  27,  28,  28,  28,  29,  28,  29,  29,  30,  30,  30,  30,  31,  30,  31,
32,  31,  32,  32,  32,  33,  32,  33,  33,  34,  33,  34,  34,  35,  34,  35,
35,  35,  35,  36,  35,  36,  37,  36,  36,  37,  37,  37,  37,  38,  37,  38,
38,  38,  39,  38,  39,  39,  39,  39,  39,  39,  40,  40,  39,  40,  40,  41,
40,  41,  40,  41,  41,  41,  41,  41,  41,  42,  41,  42,  41,  42,  42,  42,
42,  42,  42,  43,  42,  43,  42,  43,  42,  43,  43,  42,  43,  43,  43,  43,
43,  43,  43,  43,  43,  44,  43,  43,  43,  43,  44,  43,  39
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.100000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_10[381] = {
54,  54,  54,  54,  54,  54,  54,  54,  54,  54,  54,  53,  54,  54,  54,  53,
54,  53,  54,  53,  53,  53,  54,  53,  53,  52,  53,  53,  52,  53,  52,  52,
53,  52,  51,  52,  52,  51,  52,  51,  51,  51,  51,  50,  51,  50,  50,  50,
50,  49,  50,  49,  49,  49,  49,  48,  48,  48,  48,  48,  47,  48,  47,  46,
47,  46,  47,  45,  46,  45,  46,  45,  44,  45,  44,  44,  43,  44,  43,  43,
42,  43,  42,  41,  42,  41,  41,  40,  41,  40,  39,  40,  39,  38,  39,  38,
38,  37,  38,  36,  37,  36,  36,  35,  36,  35,  34,  34,  34,  33,  34,  32,
33,  32,  31,  32,  31,  30,  31,  29,  30,  29,  29,  28,  28,  28,  27,  27,
26,  26,  26,  25,  25,  24,  25,  23,  23,  23,  23,  22,  22,  21,  21,  20,
20,  20,  19,  19,  18,  18,  17,  17,  17,  16,  16,  15,  15,  15,  14,  14,
13,  13,  12,  12,  11,  11,  11,  10,  10,   9,   9,   9,   8,   7,   7,   7,
6,   6,   5,   5,   4,   4,   4,   3,   3,   2,   2,   1,   1,   0,   0,   0,
2,   1,   2,   2,   3,   3,   4,   4,   4,   5,   5,   6,   6,   7,   7,   8,
8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  12,  13,  13,  14,  14,  14,
15,  16,  16,  16,  16,  18,  17,  18,  18,  19,  19,  20,  20,  20,  21,  21,
22,  22,  23,  23,  23,  24,  24,  24,  25,  25,  26,  26,  27,  26,  28,  27,
28,  29,  28,  29,  30,  30,  30,  31,  31,  31,  32,  32,  32,  33,  33,  34,
33,  35,  34,  35,  35,  36,  36,  36,  36,  37,  37,  38,  38,  38,  38,  39,
39,  40,  39,  40,  41,  40,  41,  41,  42,  41,  42,  43,  42,  43,  43,  44,
43,  44,  44,  45,  45,  44,  46,  45,  46,  46,  46,  46,  47,  47,  47,  47,
47,  48,  48,  48,  48,  49,  48,  49,  49,  50,  49,  50,  49,  50,  51,  50,
50,  51,  51,  51,  51,  51,  51,  52,  51,  52,  52,  52,  52,  52,  53,  52,
53,  52,  53,  53,  53,  53,  53,  53,  54,  53,  53,  54,  53,  54,  54,  53,
54,  54,  54,  54,  54,  53,  54,  54,  54,  54,  54,  55,  48
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.120000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_12[381] = {
65,  65,  65,  64,  65,  65,  65,  64,  65,  65,  64,  65,  64,  65,  64,  65,
64,  64,  64,  64,  64,  64,  64,  63,  64,  63,  64,  63,  63,  63,  63,  62,
63,  62,  62,  63,  62,  61,  62,  61,  62,  61,  61,  60,  61,  60,  60,  60,
60,  60,  59,  59,  59,  58,  59,  58,  58,  58,  57,  57,  57,  57,  56,  57,
55,  56,  55,  56,  54,  55,  54,  54,  53,  54,  53,  52,  53,  52,  52,  51,
51,  51,  50,  50,  50,  49,  50,  48,  49,  48,  47,  47,  47,  47,  46,  46,
45,  45,  45,  44,  44,  43,  43,  43,  42,  42,  41,  41,  41,  40,  40,  39,
39,  38,  38,  38,  37,  37,  36,  36,  35,  35,  35,  34,  33,  33,  33,  32,
32,  31,  31,  30,  30,  30,  28,  29,  28,  27,  27,  27,  26,  25,  25,  25,
24,  23,  23,  23,  22,  21,  21,  21,  20,  19,  19,  18,  18,  18,  17,  16,
16,  15,  15,  14,  14,  14,  12,  12,  12,  11,  11,  10,  10,   9,   8,   8,
8,   7,   6,   6,   5,   5,   4,   4,   3,   3,   2,   2,   1,   0,   0,   0,
3,   1,   2,   3,   3,   4,   4,   5,   5,   6,   7,   7,   7,   8,   9,   9,
9,  11,  10,  11,  12,  12,  13,  13,  14,  15,  14,  16,  16,  16,  17,  17,
18,  19,  19,  19,  20,  21,  21,  21,  22,  23,  23,  24,  24,  24,  25,  26,
26,  26,  27,  28,  27,  29,  29,  29,  30,  30,  31,  31,  32,  32,  33,  33,
34,  34,  34,  35,  36,  36,  36,  37,  37,  37,  38,  39,  39,  39,  40,  40,
41,  41,  41,  42,  42,  43,  43,  43,  44,  44,  45,  45,  46,  45,  46,  47,
47,  47,  48,  48,  48,  49,  49,  49,  50,  50,  51,  50,  51,  52,  52,  52,
52,  53,  53,  53,  54,  54,  54,  54,  55,  55,  56,  55,  56,  56,  57,  56,
57,  58,  57,  58,  58,  58,  58,  59,  59,  59,  59,  60,  60,  59,  61,  60,
61,  60,  61,  61,  62,  61,  62,  61,  62,  62,  63,  62,  63,  62,  63,  63,
63,  63,  64,  63,  64,  63,  64,  64,  64,  64,  64,  64,  64,  65,  64,  65,
64,  65,  64,  65,  65,  64,  65,  65,  65,  65,  64,  65,  59
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.140000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_14[381] = {
76,  75,  76,  76,  75,  76,  75,  76,  75,  76,  75,  75,  76,  75,  75,  75,
75,  75,  75,  74,  75,  74,  75,  74,  74,  74,  74,  74,  73,  74,  73,  73,
73,  73,  73,  72,  72,  72,  72,  72,  71,  72,  71,  71,  70,  71,  70,  70,
69,  70,  69,  69,  69,  68,  68,  68,  68,  67,  67,  67,  66,  66,  66,  66,
65,  65,  64,  65,  64,  63,  63,  63,  63,  62,  62,  61,  61,  61,  60,  60,
60,  59,  59,  58,  58,  58,  57,  57,  56,  56,  56,  55,  55,  54,  54,  53,
53,  53,  52,  51,  51,  51,  50,  50,  49,  49,  48,  48,  48,  46,  47,  46,
45,  45,  44,  44,  43,  43,  43,  41,  42,  40,  41,  39,  40,  38,  38,  38,
37,  36,  36,  36,  34,  35,  33,  34,  32,  32,  32,  30,  31,  29,  30,  28,
28,  28,  26,  27,  25,  26,  24,  24,  23,  23,  22,  22,  20,  21,  20,  19,
18,  18,  17,  17,  16,  16,  14,  15,  13,  13,  13,  12,  11,  10,  10,  10,
8,   8,   8,   7,   6,   5,   5,   5,   4,   3,   2,   2,   1,   1,   0,   1,
1,   2,   2,   4,   3,   5,   5,   5,   7,   6,   8,   8,   9,   9,  10,  11,
11,  12,  12,  13,  14,  14,  15,  16,  16,  16,  18,  18,  18,  19,  20,  20,
21,  22,  22,  23,  23,  24,  25,  25,  25,  27,  27,  27,  28,  29,  29,  30,
30,  31,  31,  32,  33,  33,  34,  34,  35,  35,  36,  37,  37,  38,  38,  38,
39,  40,  40,  41,  42,  41,  43,  43,  43,  44,  44,  45,  45,  46,  47,  47,
47,  48,  48,  49,  49,  50,  50,  51,  51,  52,  52,  52,  53,  54,  54,  54,
55,  55,  55,  56,  57,  56,  58,  57,  58,  59,  59,  59,  59,  60,  61,  61,
61,  61,  62,  62,  63,  63,  63,  64,  63,  65,  64,  65,  65,  66,  66,  66,
66,  67,  67,  68,  67,  68,  68,  69,  68,  69,  69,  70,  70,  70,  70,  70,
71,  71,  71,  71,  71,  72,  72,  72,  72,  73,  73,  72,  73,  73,  74,  73,
74,  73,  74,  74,  74,  75,  74,  75,  74,  75,  75,  75,  74,  76,  75,  75,
75,  75,  76,  75,  76,  75,  76,  75,  76,  76,  75,  76,  68
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.160000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_16[381] = {
86,  87,  86,  87,  86,  87,  86,  86,  87,  86,  86,  86,  86,  86,  86,  86,
85,  86,  85,  86,  85,  85,  85,  85,  85,  84,  84,  85,  84,  84,  84,  83,
83,  84,  83,  82,  83,  82,  83,  81,  82,  82,  81,  81,  81,  80,  80,  80,
80,  79,  79,  79,  78,  79,  78,  77,  77,  77,  77,  76,  76,  76,  75,  75,
74,  74,  74,  74,  73,  72,  73,  72,  71,  71,  71,  70,  70,  69,  69,  69,
68,  67,  68,  66,  67,  66,  65,  65,  64,  64,  64,  63,  62,  62,  62,  61,
60,  60,  60,  59,  58,  58,  58,  56,  57,  55,  56,  54,  54,  54,  53,  52,
52,  51,  51,  50,  50,  49,  48,  48,  47,  47,  46,  45,  45,  44,  43,  43,
43,  41,  41,  41,  40,  39,  38,  38,  37,  37,  36,  35,  35,  34,  33,  33,
32,  31,  31,  30,  29,  29,  28,  27,  27,  26,  25,  25,  24,  23,  22,  22,
21,  21,  20,  19,  18,  18,  17,  16,  16,  14,  15,  13,  13,  12,  11,  11,
10,   9,   9,   7,   8,   6,   6,   5,   4,   3,   3,   2,   2,   1,   0,   1,
2,   2,   3,   3,   5,   5,   5,   7,   7,   8,   8,  10,  10,  10,  12,  12,
13,  13,  14,  15,  16,  16,  17,  18,  18,  19,  20,  21,  21,  22,  22,  24,
24,  24,  25,  26,  27,  27,  28,  29,  30,  30,  30,  32,  32,  32,  34,  34,
34,  36,  36,  36,  38,  38,  38,  39,  40,  41,  41,  41,  43,  43,  43,  44,
45,  46,  46,  46,  47,  48,  49,  48,  50,  50,  51,  51,  52,  53,  53,  53,
54,  55,  55,  56,  56,  57,  58,  58,  58,  59,  59,  60,  61,  61,  62,  62,
62,  63,  64,  64,  64,  65,  66,  65,  67,  67,  67,  67,  69,  68,  69,  70,
69,  71,  70,  71,  72,  72,  72,  73,  73,  73,  74,  74,  75,  75,  75,  76,
75,  77,  76,  77,  78,  77,  78,  78,  79,  79,  79,  79,  80,  80,  80,  80,
81,  81,  81,  82,  81,  82,  83,  82,  82,  83,  83,  84,  83,  83,  84,  84,
84,  85,  84,  85,  84,  85,  85,  85,  85,  86,  85,  86,  86,  85,  86,  86,
86,  86,  86,  87,  86,  86,  86,  87,  86,  87,  86,  87,  78
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.180000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_18[381] = {
97,  98,  97,  97,  97,  97,  98,  97,  97,  97,  97,  96,  97,  97,  96,  97,
96,  97,  96,  96,  96,  95,  96,  96,  95,  95,  95,  95,  94,  95,  94,  94,
94,  93,  94,  93,  93,  92,  93,  92,  92,  92,  91,  91,  91,  90,  91,  89,
90,  89,  89,  89,  88,  88,  88,  87,  87,  87,  86,  86,  85,  85,  85,  84,
84,  83,  83,  83,  82,  82,  81,  81,  80,  80,  80,  79,  78,  78,  78,  77,
77,  76,  75,  76,  74,  74,  74,  73,  72,  72,  72,  71,  70,  70,  69,  68,
69,  67,  67,  66,  66,  65,  65,  64,  63,  63,  62,  61,  61,  60,  60,  59,
58,  58,  57,  56,  56,  55,  55,  53,  54,  52,  52,  51,  50,  50,  49,  48,
48,  46,  47,  45,  45,  44,  43,  43,  42,  41,  40,  40,  39,  38,  38,  36,
36,  36,  34,  34,  33,  32,  32,  30,  30,  30,  28,  28,  27,  26,  25,  25,
24,  23,  22,  21,  21,  20,  19,  18,  18,  17,  15,  16,  14,  14,  12,  12,
12,  10,  10,   8,   8,   7,   7,   5,   5,   4,   3,   3,   1,   1,   0,   2,
1,   3,   3,   4,   5,   5,   7,   7,   8,   9,  10,  10,  11,  12,  13,  14,
14,  15,  16,  17,  18,  18,  19,  20,  21,  21,  23,  23,  23,  25,  25,  27,
27,  27,  29,  29,  30,  31,  31,  33,  33,  33,  35,  35,  36,  37,  38,  38,
39,  40,  40,  41,  42,  43,  43,  44,  45,  46,  46,  47,  47,  49,  49,  49,
51,  51,  52,  52,  53,  54,  54,  55,  56,  57,  57,  57,  59,  59,  59,  61,
61,  61,  62,  63,  63,  64,  65,  65,  66,  66,  67,  68,  68,  68,  70,  69,
71,  71,  71,  72,  73,  73,  73,  74,  75,  75,  76,  76,  77,  77,  77,  78,
79,  79,  80,  80,  80,  81,  81,  82,  82,  83,  83,  83,  84,  84,  85,  85,
86,  85,  87,  86,  87,  87,  88,  88,  88,  89,  89,  89,  90,  90,  90,  90,
91,  91,  92,  91,  92,  93,  92,  93,  93,  93,  93,  94,  94,  94,  94,  94,
95,  95,  95,  95,  95,  95,  96,  96,  96,  96,  96,  96,  97,  96,  97,  96,
97,  97,  97,  97,  97,  97,  97,  97,  98,  97,  97,  97,  88
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.200000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_20[381] = {
108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 107, 108, 107, 108, 107, 107,
108, 106, 107, 107, 107, 106, 106, 106, 106, 106, 105, 106, 105, 105, 104, 105,
104, 104, 104, 103, 104, 102, 103, 103, 102, 102, 101, 101, 101, 101, 100, 100,
99, 100,  98,  99,  98,  98,  97,  97,  97,  96,  96,  95,  95,  94,  94,  94,
93,  93,  92,  92,  91,  91,  90,  90,  89,  89,  89,  87,  88,  86,  87,  85,
86,  84,  84,  84,  82,  83,  82,  81,  80,  80,  80,  78,  78,  78,  77,  76,
76,  75,  74,  74,  73,  72,  72,  71,  70,  70,  69,  68,  68,  67,  66,  66,
65,  64,  63,  63,  62,  61,  60,  60,  59,  58,  58,  56,  56,  55,  55,  53,
53,  52,  52,  50,  50,  49,  48,  47,  47,  46,  45,  44,  43,  43,  41,  41,
40,  39,  39,  37,  37,  36,  35,  34,  33,  32,  32,  31,  30,  29,  28,  27,
27,  25,  25,  24,  23,  22,  21,  20,  20,  19,  17,  17,  16,  15,  14,  14,
12,  12,  10,  10,   9,   8,   7,   6,   6,   4,   4,   2,   2,   1,   0,   1,
 2,   3,   3,   5,   5,   6,   7,   8,   9,  10,  11,  11,  13,  13,  15,  15,
16,  17,  17,  19,  19,  21,  21,  22,  23,  24,  25,  26,  26,  27,  29,  29,
30,  30,  32,  33,  33,  34,  35,  36,  37,  37,  39,  39,  40,  41,  41,  43,
43,  44,  45,  46,  47,  47,  48,  49,  50,  51,  51,  52,  53,  54,  54,  55,
56,  57,  58,  58,  59,  60,  60,  61,  62,  63,  63,  65,  64,  66,  66,  67,
68,  68,  69,  70,  70,  71,  72,  73,  73,  73,  75,  75,  76,  76,  77,  77,
78,  79,  80,  80,  80,  81,  82,  82,  83,  84,  84,  85,  85,  85,  87,  86,
88,  88,  88,  89,  89,  90,  90,  91,  92,  91,  93,  92,  93,  94,  94,  95,
95,  95,  96,  96,  96,  97,  98,  98,  98,  98,  99,  99, 100, 100, 100, 101,
101, 101, 101, 102, 102, 103, 102, 103, 104, 103, 104, 104, 104, 105, 104, 105,
105, 106, 105, 106, 106, 106, 106, 107, 106, 107, 107, 107, 107, 107, 107, 108,
107, 108, 107, 108, 108, 108, 108, 108, 108, 108, 108, 108,  98
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.220000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_22[381] = {
119, 119, 119, 119, 118, 119, 119, 118, 119, 119, 118, 118, 119, 118, 118, 118,
118, 117, 118, 117, 117, 117, 117, 117, 116, 117, 116, 116, 115, 116, 115, 115,
114, 115, 114, 114, 113, 114, 112, 113, 112, 112, 112, 111, 111, 111, 110, 110,
110, 109, 109, 108, 108, 107, 107, 107, 106, 106, 105, 105, 105, 104, 103, 103,
103, 102, 101, 101, 100, 100, 100,  98,  99,  97,  98,  96,  96,  96,  94,  95,
93,  93,  93,  92,  91,  90,  90,  90,  88,  88,  87,  87,  86,  85,  85,  84,
83,  82,  82,  81,  81,  79,  79,  78,  78,  76,  76,  75,  75,  73,  73,  72,
72,  70,  70,  69,  68,  67,  67,  65,  65,  64,  64,  62,  61,  61,  60,  59,
58,  58,  56,  56,  54,  54,  53,  52,  51,  51,  49,  49,  47,  47,  46,  45,
44,  43,  42,  41,  41,  39,  38,  38,  37,  35,  35,  34,  33,  32,  31,  30,
29,  28,  27,  26,  26,  24,  23,  23,  21,  21,  19,  19,  17,  17,  15,  15,
14,  12,  12,  11,  10,   8,   8,   7,   6,   5,   4,   3,   2,   1,   0,   1,
2,   3,   4,   5,   6,   7,   8,   9,  10,  10,  12,  13,  14,  14,  16,  17,
17,  19,  19,  21,  21,  23,  23,  25,  25,  26,  27,  29,  29,  30,  31,  32,
33,  34,  34,  36,  37,  37,  39,  39,  41,  41,  42,  43,  44,  45,  46,  47,
48,  48,  50,  50,  51,  52,  53,  54,  55,  56,  56,  58,  58,  59,  60,  60,
62,  62,  64,  64,  65,  65,  67,  67,  68,  69,  70,  71,  71,  72,  73,  74,
74,  75,  76,  77,  77,  79,  79,  79,  81,  81,  82,  82,  83,  84,  85,  85,
86,  87,  87,  88,  89,  89,  90,  91,  91,  92,  92,  93,  94,  94,  95,  95,
96,  97,  97,  98,  98,  99,  99, 100, 101, 101, 101, 102, 103, 103, 103, 104,
105, 105, 105, 106, 106, 107, 107, 107, 108, 109, 108, 109, 110, 110, 110, 111,
111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 114, 115, 115, 115, 115,
116, 116, 116, 116, 117, 116, 117, 117, 117, 118, 117, 118, 118, 118, 118, 118,
118, 119, 118, 119, 118, 119, 119, 118, 119, 119, 119, 119, 107
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.240000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_24[381] = {
130, 129, 130, 130, 129, 130, 129, 130, 129, 130, 129, 129, 129, 129, 129, 128,
129, 128, 128, 128, 128, 128, 127, 128, 127, 127, 126, 127, 126, 126, 125, 126,
125, 124, 125, 124, 124, 124, 123, 123, 122, 122, 122, 122, 121, 120, 121, 120,
119, 119, 119, 118, 118, 117, 117, 116, 116, 115, 115, 115, 114, 113, 113, 112,
112, 111, 111, 110, 110, 109, 108, 108, 107, 107, 106, 105, 105, 104, 103, 103,
102, 102, 101, 100,  99,  99,  98,  97,  97,  96,  95,  95,  94,  93,  92,  91,
91,  90,  89,  89,  87,  87,  86,  86,  84,  84,  82,  82,  82,  80,  79,  79,
78,  77,  76,  75,  74,  74,  72,  72,  71,  70,  69,  68,  67,  66,  65,  65,
63,  63,  61,  61,  59,  59,  58,  57,  56,  54,  54,  53,  52,  51,  50,  49,
48,  47,  46,  45,  44,  43,  42,  41,  40,  39,  38,  37,  36,  35,  33,  33,
32,  31,  29,  29,  28,  26,  26,  24,  23,  23,  21,  20,  19,  18,  17,  16,
15,  14,  13,  12,  10,  10,   9,   7,   6,   6,   4,   3,   2,   1,   0,   2,
2,   3,   5,   5,   6,   8,   8,  10,  11,  12,  12,  14,  15,  16,  17,  19,
19,  20,  21,  23,  23,  25,  25,  27,  27,  29,  30,  30,  32,  33,  34,  35,
36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,
52,  53,  54,  55,  56,  57,  58,  58,  60,  61,  61,  63,  63,  65,  65,  66,
68,  68,  69,  70,  70,  72,  73,  73,  75,  75,  76,  77,  78,  78,  80,  80,
81,  82,  83,  84,  84,  86,  86,  87,  87,  89,  89,  90,  91,  92,  92,  93,
94,  94,  96,  96,  96,  98,  98,  99,  99, 100, 101, 102, 102, 103, 103, 104,
105, 105, 106, 107, 107, 108, 109, 109, 109, 110, 111, 111, 112, 113, 112, 114,
114, 114, 115, 115, 116, 117, 117, 117, 118, 118, 119, 119, 119, 120, 120, 121,
121, 122, 121, 123, 122, 123, 123, 124, 124, 124, 124, 125, 125, 126, 125, 126,
126, 127, 126, 127, 127, 128, 127, 128, 128, 128, 128, 128, 129, 128, 129, 129,
129, 129, 130, 129, 129, 130, 129, 130, 129, 130, 130, 129, 118
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.260000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_26[381] = {
141, 140, 141, 140, 140, 141, 140, 140, 140, 141, 140, 139, 140, 140, 139, 140,
139, 139, 139, 139, 138, 138, 139, 137, 138, 137, 138, 137, 136, 137, 136, 136,
135, 135, 135, 135, 134, 134, 133, 133, 133, 132, 132, 132, 131, 131, 130, 130,
129, 129, 129, 128, 127, 128, 126, 126, 126, 125, 124, 124, 124, 122, 123, 121,
121, 121, 120, 119, 119, 118, 117, 117, 116, 116, 115, 114, 113, 113, 112, 111,
111, 110, 109, 109, 107, 108, 106, 105, 105, 104, 103, 102, 102, 101, 100,  99,
98,  98,  96,  96,  95,  94,  93,  93,  91,  91,  90,  88,  88,  87,  87,  85,
84,  83,  83,  81,  81,  79,  79,  77,  77,  76,  74,  74,  73,  72,  70,  70,
69,  68,  66,  66,  65,  63,  63,  61,  61,  59,  59,  57,  56,  56,  54,  53,
52,  51,  50,  48,  48,  47,  45,  45,  43,  42,  41,  40,  39,  38,  36,  36,
34,  33,  33,  31,  29,  29,  28,  26,  26,  24,  23,  22,  20,  20,  19,  17,
16,  15,  14,  13,  11,  10,  10,   8,   7,   5,   5,   4,   2,   1,   0,   2,
3,   3,   5,   6,   7,   8,   9,  10,  12,  13,  14,  15,  16,  17,  19,  20,
20,  22,  23,  25,  25,  27,  27,  29,  30,  31,  32,  33,  35,  35,  37,  38,
39,  40,  41,  42,  44,  44,  46,  46,  48,  49,  50,  51,  52,  53,  54,  55,
57,  57,  58,  60,  61,  61,  63,  63,  65,  66,  67,  67,  69,  70,  71,  72,
72,  74,  75,  76,  76,  78,  79,  79,  81,  81,  83,  83,  84,  86,  86,  87,
88,  89,  89,  91,  92,  92,  93,  94,  95,  96,  97,  97,  99,  99, 100, 101,
101, 103, 103, 104, 105, 105, 107, 107, 107, 109, 109, 110, 111, 111, 112, 113,
114, 114, 115, 115, 116, 117, 118, 118, 119, 119, 120, 120, 121, 122, 122, 123,
124, 124, 124, 125, 126, 126, 126, 128, 127, 128, 129, 129, 129, 130, 130, 131,
131, 132, 132, 132, 133, 133, 134, 134, 134, 134, 135, 135, 136, 136, 136, 136,
137, 137, 137, 137, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 140, 139,
140, 140, 140, 140, 140, 141, 140, 140, 141, 140, 141, 140, 127
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.280000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_28[381] = {
151, 152, 151, 151, 151, 152, 151, 151, 151, 151, 150, 151, 150, 151, 150, 150,
150, 150, 149, 150, 149, 149, 149, 148, 148, 148, 148, 148, 147, 147, 146, 146,
146, 146, 145, 145, 145, 144, 143, 144, 143, 142, 142, 142, 141, 141, 141, 139,
140, 139, 138, 138, 137, 137, 136, 136, 135, 135, 134, 134, 132, 133, 131, 131,
131, 130, 129, 128, 128, 127, 127, 125, 125, 125, 123, 123, 123, 121, 121, 120,
119, 118, 118, 117, 116, 115, 115, 113, 113, 112, 111, 110, 110, 108, 108, 107,
105, 105, 104, 104, 102, 101, 101,  99,  99,  97,  97,  96,  94,  94,  93,  91,
91,  90,  89,  87,  87,  86,  84,  84,  82,  82,  80,  80,  78,  77,  77,  75,
74,  73,  71,  71,  70,  68,  68,  66,  65,  64,  63,  62,  60,  60,  58,  57,
56,  55,  54,  52,  52,  50,  49,  48,  46,  46,  44,  43,  42,  41,  39,  38,
37,  36,  35,  33,  32,  31,  30,  28,  28,  26,  25,  23,  23,  21,  20,  18,
18,  16,  15,  13,  13,  11,  10,   9,   7,   6,   5,   4,   2,   2,   0,   2,
2,   4,   5,   6,   8,   9,  10,  11,  12,  14,  15,  16,  18,  18,  20,  21,
23,  24,  24,  27,  27,  28,  30,  31,  32,  34,  35,  35,  37,  39,  39,  41,
42,  43,  44,  46,  46,  48,  49,  51,  51,  53,  53,  55,  56,  57,  59,  59,
61,  62,  63,  64,  65,  66,  68,  68,  70,  71,  72,  73,  74,  75,  76,  78,
78,  79,  81,  81,  83,  84,  84,  86,  87,  88,  88,  90,  91,  92,  93,  93,
95,  96,  96,  98,  99,  99, 101, 101, 102, 103, 105, 105, 106, 106, 108, 109,
109, 110, 111, 112, 113, 114, 114, 116, 116, 117, 117, 119, 119, 120, 121, 121,
122, 123, 124, 124, 126, 125, 127, 127, 128, 128, 130, 129, 131, 131, 132, 132,
133, 133, 134, 135, 135, 136, 136, 137, 138, 138, 138, 139, 139, 140, 141, 140,
142, 141, 142, 143, 143, 143, 144, 144, 145, 145, 145, 146, 146, 146, 146, 147,
147, 148, 148, 148, 148, 148, 149, 149, 149, 150, 149, 150, 150, 150, 150, 151,
150, 151, 151, 151, 150, 152, 151, 151, 151, 151, 152, 151, 137
};

//length = 381
//Freq = 31.500000 KHz, AMP = 0.300000,Fs = 24.000000MHz
static u32 kiss_data_Fs_24M_f_31500_AMP_0_30[381] = {
162, 162, 162, 162, 162, 162, 162, 162, 162, 162, 161, 161, 162, 161, 161, 161,
160, 161, 160, 160, 160, 159, 160, 159, 159, 158, 159, 158, 157, 158, 157, 156,
157, 156, 155, 155, 155, 155, 154, 153, 154, 152, 153, 151, 152, 151, 150, 150,
149, 149, 148, 148, 147, 147, 146, 145, 145, 144, 144, 143, 142, 142, 141, 140,
140, 139, 139, 137, 137, 136, 136, 135, 134, 133, 132, 132, 131, 130, 130, 128,
128, 127, 126, 125, 124, 124, 122, 122, 121, 120, 119, 118, 117, 116, 116, 114,
114, 112, 112, 110, 110, 108, 108, 106, 106, 105, 103, 103, 101, 100, 100,  98,
97,  96,  95,  94,  93,  92,  91,  89,  89,  87,  86,  85,  84,  83,  82,  80,
80,  78,  77,  75,  75,  73,  73,  71,  69,  69,  67,  67,  65,  63,  63,  61,
60,  59,  57,  57,  55,  53,  53,  51,  50,  49,  47,  46,  45,  44,  42,  41,
40,  38,  37,  36,  34,  33,  32,  31,  29,  28,  26,  26,  24,  22,  22,  20,
18,  18,  16,  14,  13,  12,  11,   9,   8,   7,   5,   4,   3,   1,   0,   3,
3,   4,   5,   7,   8,   9,  11,  12,  13,  15,  16,  18,  18,  20,  22,  22,
24,  26,  26,  28,  30,  30,  32,  33,  35,  36,  37,  38,  40,  41,  42,  44,
45,  46,  48,  48,  50,  52,  52,  54,  55,  56,  58,  59,  60,  61,  63,  63,
65,  67,  67,  69,  70,  71,  72,  73,  75,  76,  77,  78,  80,  80,  82,  83,
84,  85,  86,  87,  89,  89,  91,  92,  93,  94,  95,  96,  98,  98,  99, 101,
101, 103, 103, 105, 106, 106, 108, 108, 110, 111, 111, 113, 113, 115, 115, 116,
118, 118, 119, 120, 121, 122, 122, 124, 124, 125, 126, 127, 128, 129, 129, 130,
131, 132, 132, 134, 134, 134, 136, 136, 137, 138, 138, 139, 140, 141, 141, 141,
143, 143, 144, 144, 145, 145, 146, 147, 147, 148, 148, 149, 149, 150, 151, 150,
152, 152, 152, 153, 153, 154, 154, 154, 155, 155, 156, 156, 156, 157, 157, 157,
158, 158, 158, 159, 159, 159, 159, 160, 160, 160, 160, 160, 161, 161, 161, 161,
161, 162, 161, 162, 162, 161, 162, 162, 162, 162, 162, 163, 146
};

#define SRAM_TEST_REG0 0x03000048

#define CCMU_BASE 0x03001000
#define CCMU_SIZE 4096

#define CCMU_PLL_VIDEO_CONTROL 0x50
#define CCMU_PLL_VIDEO_BIAS 0x350

#define CCMU_PLL_VIDEO_PATTERN0_CONTROL 0x150
#define CCMU_PLL_VIDEO_PATTERN1_CONTROL 0x154

#define CCMU_TCON_TV0 0xb80

static void ccmu_tcon_tv_set(u32 pixel_clk)
{
	u32 ccmu_base;

	ccmu_base = CCMU_BASE;

	switch (pixel_clk) {
	case 74250000:
		writel(0x84000009, ccmu_base + CCMU_TCON_TV0);
		break;
	case 148500000:
		writel(0x84000004, ccmu_base + CCMU_TCON_TV0);
		break;
	case 297000000:
		writel(0x85000104, ccmu_base + CCMU_TCON_TV0);
		break;
	default:
		break;
	}
}

static void ccmu_pll_video_control_set(u32 pixel_clk)
{
	u32 ccmu_base = CCMU_BASE;

	writel(0xa0007a00 | (1 << 27) | (1 << 24),
		ccmu_base + CCMU_PLL_VIDEO_CONTROL);
}

static void ccmu_pll_video_bias_set(u32 pixel_clk)
{
	u32 ccmu_base = CCMU_BASE;

	switch (pixel_clk) {
	case 74250000:
		writel(0x00080000, ccmu_base + CCMU_PLL_VIDEO_BIAS);
		break;
	case 148500000:
		writel(0x00020000, ccmu_base + CCMU_PLL_VIDEO_BIAS);
		break;
	case 297000000:
		writel(0x0, ccmu_base + CCMU_PLL_VIDEO_BIAS);
		break;
	default:
		break;
	}
}


//write SDM wavedata into PLL SDM sram
static u32 ccmu_sram_pat_cfg(u32 *cfg_table, u32 num)
{
	u32 i;
	u32 rdata;
	u32 sram_test_reg;
	u32 ccmu_base;

	sram_test_reg = SRAM_TEST_REG0;
	writel(readl(sram_test_reg) | (1 << 20), sram_test_reg);

	ccmu_base = CCMU_BASE;
	/*reset sram*/
	for (i = 0; i < 382; i++)
		writel(0, ccmu_base + i * 0x4);

	for (i = 0; i < num; i++)
		writel(cfg_table[i], ccmu_base + i * 4);

	/*check data*/
	for (i = 0; i < 382; i++) {
		rdata = readl(ccmu_base + i * 0x4);
		if (i < num) {
			if (rdata != cfg_table[i]) {
				printf("ccmu sram test fail!\n");
				break;
			}

		} else {
			if (rdata != 0) {
				printf("ccmu sram test fail!\n");
				break;
			}
		}
	}

	writel(readl(sram_test_reg) & 0xffefffff, sram_test_reg);

	return 0;
}

//write SDM wavedata into PLL SDM sram
static u32 ccmu_sram_pat_uncfg(void)
{
	u32 i;

	u32 sram_test_reg;
	u32 ccmu_base;

	sram_test_reg = SRAM_TEST_REG0;
	writel(readl(sram_test_reg) | (1 << 20), sram_test_reg);

	ccmu_base = CCMU_BASE;
	/*reset sram*/
	for (i = 0; i < 382; i++)
		writel(0, ccmu_base + i * 0x4);

	writel(readl(sram_test_reg) & 0xffefffff, sram_test_reg);

	return 0;
}

static u32 ccmu_sdm_mode_set(u8 hershey)
{
	u32 rvalue;
	u32 ccmu_base;

	ccmu_base = CCMU_BASE;

	if (hershey) {
		rvalue = readl(ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		rvalue &= ~(0x1 << 31);
		writel(rvalue, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);

		udelay(1000);

		rvalue = readl(ccmu_base + CCMU_PLL_VIDEO_PATTERN1_CONTROL);
		rvalue &= ~(0x1 << 31);
		rvalue |= (0x1 << 31);
		writel(rvalue, ccmu_base + CCMU_PLL_VIDEO_PATTERN1_CONTROL);

		udelay(1000);
	} else {
		rvalue = readl(ccmu_base + CCMU_PLL_VIDEO_PATTERN1_CONTROL);
		rvalue &= ~(0x1 << 31);
		writel(rvalue, ccmu_base + CCMU_PLL_VIDEO_PATTERN1_CONTROL);

		udelay(1000);

		rvalue = readl(ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		rvalue &= ~(0x1 << 31);
		writel(rvalue, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);

		udelay(1000);
	}

	return 0;
}

static void ccmu_pll_video_pattern_set_amp(u32 amp)
{
	u32 ccmu_base;

	ccmu_base = CCMU_BASE;

	switch (amp) {
	case 2://sdm amp = 0.02
		writel(0xC0717AE1, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 4://sdm amp = 0.04
		writel(0xC0E175C3, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 6://sdm amp = 0.06
		writel(0xC15170A4, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 8://sdm amp = 0.08
		writel(0xC1C16B85, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 10://sdm amp = 0.10
		writel(0xC2216666, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 12://sdm amp = 0.12
		writel(0xC2916148, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 14://sdm amp = 0.14
		writel(0xC3015C29, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 16://sdm amp = 0.16
		writel(0xC371570A, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 18://sdm amp = 0.18
		writel(0xC3E151EC, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 20://sdm amp = 0.20
		writel(0xC4514CCD, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 22://sdm amp = 0.22
		writel(0xC4C147AE, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 24://sdm amp = 0.24
		writel(0xC531428F, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 26://sdm amp = 0.26
		writel(0xC5913D71, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 28://sdm amp = 0.28
		writel(0xC6013852, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	case 30://sdm amp = 0.30
		writel(0xC6713333, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;

	default://sdm amp = 0.10
		writel(0xC2216666, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
		break;
	}
}

static void ccmu_pll_video_pattern_unset_amp(void)
{
	u32 ccmu_base;

	ccmu_base = CCMU_BASE;

	writel(0x0, ccmu_base + CCMU_PLL_VIDEO_PATTERN0_CONTROL);
}

static u32 hdmi_pll_sdm_Fs_24M_f_31500(u32 amp, bool old)
{
	u32 *table;
	u32 table_size = 0;

	switch (amp) {
	case 2://sdm amp = 0.02
		table = kiss_data_Fs_24M_f_31500_AMP_0_02;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_02);
		break;

	case 4://sdm amp = 0.04
		table = kiss_data_Fs_24M_f_31500_AMP_0_04;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_04);
		break;

	case 6://sdm amp = 0.06
		table = kiss_data_Fs_24M_f_31500_AMP_0_06;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_06);
		break;

	case 8://sdm amp = 0.08
		table = kiss_data_Fs_24M_f_31500_AMP_0_08;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_08);
		break;

	case 10://sdm amp = 0.10
		table = kiss_data_Fs_24M_f_31500_AMP_0_10;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_10);
		break;

	case 12://sdm amp = 0.12
		table = kiss_data_Fs_24M_f_31500_AMP_0_12;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_12);
		break;

	case 14://sdm amp = 0.14
		table = kiss_data_Fs_24M_f_31500_AMP_0_14;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_14);
		break;

	case 16://sdm amp = 0.16
		table = kiss_data_Fs_24M_f_31500_AMP_0_16;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_16);
		break;

	case 18://sdm amp = 0.18
		table = kiss_data_Fs_24M_f_31500_AMP_0_18;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_18);
		break;

	case 20://sdm amp = 0.20
		table = kiss_data_Fs_24M_f_31500_AMP_0_20;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_20);
		break;

	case 22://sdm amp = 0.22
		table = kiss_data_Fs_24M_f_31500_AMP_0_22;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_22);
		break;

	case 24://sdm amp = 0.24
		table = kiss_data_Fs_24M_f_31500_AMP_0_24;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_24);
		break;

	case 26://sdm amp = 0.26
		table = kiss_data_Fs_24M_f_31500_AMP_0_26;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_26);
		break;

	case 28://sdm amp = 0.28
		table = kiss_data_Fs_24M_f_31500_AMP_0_28;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_28);
		break;

	case 30://sdm amp = 0.30
		table = kiss_data_Fs_24M_f_31500_AMP_0_30;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_30);
		break;

	default://sdm amp = 0.10
		table = kiss_data_Fs_24M_f_31500_AMP_0_10;
		table_size = sizeof(kiss_data_Fs_24M_f_31500_AMP_0_10);
		break;
	}

	if (old) {
		ccmu_sdm_mode_set(0);
	} else {
		ccmu_sdm_mode_set(1);//enable new hershey kiss sdm
		ccmu_sram_pat_cfg(table, table_size / 4);//write sdm wavedata into sdm sram
	}

	ccmu_pll_video_pattern_set_amp(amp);

	return table_size;
}

u32 hdmi_pll_video2_sdm_set(u32 Fs, u32 f, u32 amp, bool old)
{
	//SDM Clk source is 24MHz
	//SDM wave freq is 31.5KHz
	if (Fs == 24000000) {
		if (f == 31500)
			hdmi_pll_sdm_Fs_24M_f_31500(amp, old);
		else if (f == 32000)  //SDM wave freq is 32KHz
			printf("not support now,support later\n");
		else if (f == 32500)  //SDM wave freq is 32.5KHz
			printf("not support now,support later\n");
		else if (f == 33000)  //SDM wave freq is 33KHz
			printf("not support now,support later\n");
	} else {//SDM Clk source is 12MHz
		if (f == 31500)
			printf("not support now,support later\n");
		else if (f == 32000)  //SDM wave freq is 32KHz
			printf("not support now,support later\n");
		else if (f == 32500)  //SDM wave freq is 32.5KHz
			printf("not support now,support later\n");
		else if (f == 33000)  //SDM wave freq is 33KHz
			printf("not support now,support later\n");
	}

	return 0;
}

static u32 sdm_src_clk_rate = 24000000;
static u32 sdm_wave_rate = 31500;
u32 ss_amp = 10;
bool ss_old;

void hdmi_unset_spread_spectrum(void)
{
	u32 ccmu_base;

	ccmu_base = CCMU_BASE;

	writel(0x000f0000, ccmu_base + 0x350);
	ccmu_pll_video_pattern_unset_amp();
	ccmu_sram_pat_uncfg();
}

void hdmi_unspread_sprectrum_set(u32 pixel_clk)
{
	u32 ccmu_base = CCMU_BASE;

	switch (pixel_clk) {
	case 13500000:
		break;
	case 27000000:
		writel(0x88006213, ccmu_base + CCMU_PLL_VIDEO_CONTROL);
		writel(0x8400000a, ccmu_base + CCMU_TCON_TV0);
		writel(0x8200000a, ccmu_base + CCMU_HDMI);
		break;
	case 74250000:
		writel(0xa8006200, ccmu_base + CCMU_PLL_VIDEO_CONTROL);
		writel(0x85000303, ccmu_base + CCMU_TCON_TV0);
		writel(0x82000003, ccmu_base + CCMU_HDMI);
		break;
	case 148500000:
		writel(0xa8006200, ccmu_base + CCMU_PLL_VIDEO_CONTROL);
		writel(0x85000301, ccmu_base + CCMU_TCON_TV0);
		writel(0x82000001, ccmu_base + CCMU_HDMI);
		break;
	case 297000000:
		writel(0xa8006200, ccmu_base + CCMU_PLL_VIDEO_CONTROL);
		writel(0x85000007, ccmu_base + CCMU_TCON_TV0);
		writel(0x82000000, ccmu_base + CCMU_HDMI);
		break;
	case 594000000:
		writel(0xa8006200, ccmu_base + CCMU_PLL_VIDEO_CONTROL);
		writel(0x85000003, ccmu_base + CCMU_TCON_TV0);
		writel(0x82000000, ccmu_base + CCMU_HDMI);
		break;
	default:
		break;
	}
}

u32 hdmi_set_spread_spectrum(u32 pixel_clk)
{
	if (!ss_amp) {
		hdmi_unset_spread_spectrum();
		hdmi_unspread_sprectrum_set(pixel_clk);
		return 0;
	}

	if (pixel_clk != 74250000
		&& pixel_clk != 148500000
		&& pixel_clk != 297000000) {
		printf("[HDMI2.0] NOT set spread spectrun, pixel clk:%d\n",
				pixel_clk);
		hdmi_unset_spread_spectrum();
		hdmi_unspread_sprectrum_set(pixel_clk);
		return 0;
	}

	printf("[HDMI2.0] set spread spectrun, pixel clk:%d\n", pixel_clk);

	ccmu_pll_video_control_set(pixel_clk);
	ccmu_tcon_tv_set(pixel_clk);
	ccmu_pll_video_bias_set(pixel_clk);

	hdmi_pll_video2_sdm_set(sdm_src_clk_rate, sdm_wave_rate, ss_amp, ss_old);

	return 0;
}
